#include "stdafx.h"
#include "State.h"
#include "Edge.h"

State::State()
{
	children = NULL;
	parents = NULL;
	q = NULL;
	cost = std::numeric_limits<double>::max();
}

State::~State()
{
	delete[] q;
	delete children;
	delete parents;
}

void State::add_parent(State* state, double cost_step, unsigned int dim_ctrl, double* ctrl)
{
	Edge* e = new Edge();
	e->set_entry(state);
	e->set_exit(this);
	e->set_cost_step(cost_step);
	e->set_dim_ctrl(dim_ctrl);
	e->set_ctrl(ctrl);

	if (parents == NULL)
		parents = new std::vector<Edge*>();
	parents->push_back(e);
}

double* State::get_parent_q()
{
	if (parents == NULL || parents->size() == 0)
		return NULL;
	State* x_parent = parents->at(0)->get_entry();
	return x_parent->q;
}